<?php

namespace app\pc\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;


class Bank extends Base
{
    public  $model;

    public function __construct()
    {
        $this->model = model("UsersBank");
        parent::__construct();
        $rows = Cache::get($this->Cstatic->get("sid"));
        $this->sid_user_id = $rows['id'];
        $this->sid_mobile = $rows['mobile'];
    }

    /**
     * 显示银行列表
     *
     * @return \think\Response
     */
    public function index()
    {//
      $where['user_id'] = $this->sid_user_id;
        //时间的处理
     $res = $this->model->bank_page($where);
     return   resJson(1,$this->ecLang("query"),$res['res'],$res['pageInfo']);
    }

    /**
     *  增加银行
     */
    public function save(){
        $data = $this->RealData;
        $data['user_id'] = $this->sidRows['id'];

        $UsersInvest = model("UsersInvest");
        $where['user_id'] = $this->sidRows['id'];
        //时间的处理
        $row = $UsersInvest->where($where)->find();

        $bank_noCount = $this->where("user_id",$this->sidRows['id'])->where("bank_no",$this->RealData['bank_no'])->count();
        if($bank_noCount>0){
            return   failJson("你添加的银行卡已存在");
        }
        if(isset($row['user_name'])&&isset($row['id_number']))
        {
            //已经绑定银行卡
            $threepart = tieCard($this->bank_no,$row['user_name'],$row['id_number'],$this->mobiles);
            //第三方绑定成功
            if($threepart['status']!=1&&$threepart['status']!=2){
                return   failJson($threepart['msg']);
            }
        }
        else{
            return   failJson("未实名认证,请先认证");
        }
            $inser_id =  $this->model->save($data);
            if(!$inser_id){
                return   failJson($this->ecLang("failInsert"));
            }
            return sucessJson($this->ecLang("scuessInsert"));

    }

    //用户认证
    public function identification(){
        $UsersInvest = model("UsersInvest");
        $where['user_id'] = $this->sid_user_id;
        //时间的处理
        $row = $UsersInvest->where($where)->find();
        if(empty($row))
        {
            return   failJson("身份未验证");
        }
        return sucessJson("已验证",$row);
    }


    //用户是否添加银行卡
    public function bankstatus(){
        $where['user_id'] = $this->sid_user_id;
        //时间的处理
        $count = $this->model->where($where)->count();
        if(!$count)
        {
        return   resJson(0,$this->ecLang("failstatus"));
        }
        return   resJson(1,$this->ecLang("sucessstatus"));

    }


    //身份信息身份认证
    public function idcardstatus(){
        $UsersInvest = model("UsersInvest");
        $where['user_id'] = $this->sid_user_id;
        //时间的处理
        $row = $UsersInvest->where($where)->find();
        if(empty($row))
        {
            return   failJson("身份未验证");
        }
        $count = $this->model->where($where)->count();
        $moneyModel = model("UsersMoney");
        $resd =  $moneyModel->where($where)->find();
        $row['count'] = $count;
        $row['mobile'] = $this->sid_mobile;
        $row['money'] = $resd['money'];
        return sucessJson("已验证",$row);

    }


}
